Skip to content

[SPIR-V] Add sampler & resource heaps for textures#8281

Open
Keenuts wants to merge 3 commits intomicrosoft:mainfrom
Keenuts:descriptor-heap
Open

[SPIR-V] Add sampler & resource heaps for textures#8281
Keenuts wants to merge 3 commits intomicrosoft:mainfrom
Keenuts:descriptor-heap

Conversation

@Keenuts
Copy link
Collaborator

@Keenuts Keenuts commented Mar 20, 2026

Resource & Sampler heaps are already implemented in DXC, but rely on an emulated heap. A new VK/SPV extension bring actual descriptor heaps. This is the first step toward a complete support.

This commits focuses on Texture/Sampler/Buffer resources, which are all backed by OpTypeImage/OpTypeSampler. This path is a bit simpler as we have no ArrayStride, nor OpAccessChain legalization issues: the whole image handle loading is handled in DXC, and the rest follows the normal path.

Next step is to implement RWStructuredBuffer/StructuredBuffer support, with counters and chain legalization.

Related to #8243

@Keenuts
Copy link
Collaborator Author

Keenuts commented Mar 20, 2026

CI failure is because of SPV tools update, requires #8278

Resource & Sampler heaps are already implemented in DXC, but rely
on an emulated heap. A new VK/SPV extension bring actual descriptor
heaps. This is the first step toward a complete support.

This commits focuses on Texture/Sampler/Buffer resources, which are
all backed by OpTypeImage/OpTypeSampler. This path is a bit simpler as
we have no ArrayStride, nor OpAccessChain legalization issues: the whole
image handle loading is handled in DXC, and the rest follows the normal
path.

Next step is to implement RWStructuredBuffer/StructuredBuffer support,
with counters and chain legalization.

Related to microsoft#8243
@Keenuts
Copy link
Collaborator Author

Keenuts commented Mar 24, 2026

Rebased on main now that SPV-tools fixes are merged.

Copy link
Collaborator

@s-perron s-perron left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you move the parts of the code that are not used (and therefore not tested) in this PR to the one where it is used?

I have a couple other ideas, but in general this is in good shape.

Comment on lines +432 to +442
def fspv_use_emulated_heap
: Flag<["-"], "fspv-use-emulated-heap">,
Group<spirv_Group>,
Flags<[CoreOption, DriverOption]>,
HelpText<
"Use emulated descriptor heap using descriptor indexing (default).">;
def fspv_use_descriptor_heap
: Flag<["-"], "fspv-use-descriptor-heap">,
Group<spirv_Group>,
Flags<[CoreOption, DriverOption]>,
HelpText<"Use SPV_EXT_descriptor_heap for HLSL descriptor heaps.">;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need two options?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about the migration for users:

  • extension is brand new, we don't want to push it
  • but long term, extension is better, so we want to encourage it.

Idea was to use the emulated by default for now, and in a future version, switch the default to use the extension, while allowing users to downgrade to emulation.
But no strong feeling about this.

Copy link
Collaborator

@s-perron s-perron Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We let fspv-use-descriptor-heap default to false now. Then if we flip it, people can use fno-spv-use-descriptor-heap. Right?

If we have the two options, we have the odd situation: what if both are set to true or both are set to false?

if (isa<ImageType>(type) || isa<SamplerType>(type) ||
isa<AccelerationStructureTypeNV>(type))
isa<AccelerationStructureTypeNV>(type) || isa<BufferEXTType>(type) ||
isa<UntypedPointerKHRType>(type))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, Untyped pointers will always be pointers to resources, but will this always be true? We may want to use untyped pointers for byte address buffers, which will be resources. We won't implement unions on DXC, so that will not be a problem. Any other situations?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure TBH, but does it matter? I suppose if we use them for something else we'll know what condition to change to refine this no?

@Keenuts Keenuts requested a review from s-perron March 24, 2026 16:45
}
HeapVar = SamplerHeapVar;
} else
assert(0 && "Unsupported heap type");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use llvm_unreachable.

Comment on lines +432 to +442
def fspv_use_emulated_heap
: Flag<["-"], "fspv-use-emulated-heap">,
Group<spirv_Group>,
Flags<[CoreOption, DriverOption]>,
HelpText<
"Use emulated descriptor heap using descriptor indexing (default).">;
def fspv_use_descriptor_heap
: Flag<["-"], "fspv-use-descriptor-heap">,
Group<spirv_Group>,
Flags<[CoreOption, DriverOption]>,
HelpText<"Use SPV_EXT_descriptor_heap for HLSL descriptor heaps.">;
Copy link
Collaborator

@s-perron s-perron Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We let fspv-use-descriptor-heap default to false now. Then if we flip it, people can use fno-spv-use-descriptor-heap. Right?

If we have the two options, we have the odd situation: what if both are set to true or both are set to false?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

2 participants